<?php

class IndexController extends Site_Controller_Action
{
    public function init()
    {
        
    }

    public function indexAction()
    {
        //$obj = new Admin_Model_DbTable_Textohome();
        //$result = $obj->fetchRow();
        //$this->view->texto = $result;
       
        $pagina = $this->_getParam('pagina', '');
        $this->view->pagina = $pagina;
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/validation/dist/jquery.validate.min.js');
        
        $sessao = new Zend_Session_Namespace('Parametros');
        $this->view->parametros  = $sessao->parametros;
        
        $fullbanner = $this->db->fetchAll('SELECT SQL_CACHE * FROM FULLBANNER WHERE BAN_STA = 1 ORDER BY BAN_ORD ASC');
        $this->view->fullbanner = $fullbanner;  
        
        
        $result = $this->db->fetchAll('SELECT SQL_CACHE * FROM PAGINA_SITE WHERE PGS_STA = 1 ORDER BY PGS_ORD ASC');
        $this->view->paginasite = $result; 
        
    }
    
    public function contatoAction()
    {
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender();
        
        $ok = false;
        
        if($this->getRequest()->isPost()) {
            try {
                $formData = $this->getRequest()->getPost();

                Zend_Loader::loadClass('envioemail','library');
                $arr['nome'] = $formData['nome'];
                $arr['email'] = $formData['email'];
                $arr['assunto'] = $formData['assunto'];
                $arr['mensagem'] = $formData['mensagem'];
                $arr['urlbase']  = $this->_urlbase;
                $arr['modulo'] = '';//contato';
                $ok = envioemail::formularioContato($arr); 
                
            } catch (Exception $exc) {
                //echo 'error: '.$exc->getMessage(); 
            }
        }
        
        echo json_encode(array('ok' => $ok));
        
    }
    
    public function produtoAction()
    {
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender();
        
        $ok = false;
        
        if($this->getRequest()->isPost()) {
            try {
                $formData = $this->getRequest()->getPost();
                
                $data = array(
                    'PRO_ID'    => $formData['produto'],
                    'INT_NOM'   => $formData['nome'],
                    'INT_TEL'   => $formData['telefone'],
                    'INT_CID'   => $formData['cidade'],
                    'INT_EML'   => $formData['email'],
                    'INT_DAT'   => date('Y-m-d'), 
                    'INT_HOR'   => date('H:i:00'),
                    'INT_MSG'   => $formData['mensagem'],
                    'INT_STA'   => 1,
                );
                
                $int = $this->db->insert('INTERESSE', $data);
                //$int_id =  $this->db->lastInsertId();
               
                $pro = $this->db->fetchRow('SELECT SQL_CACHE PRO_NOM FROM PRODUTO WHERE PRO_ID = '.$formData['produto']);
                
                Zend_Loader::loadClass('envioemail','library');
                $arr['produto'] = $pro['PRO_NOM'];
                $arr['nome'] = $formData['nome'];
                $arr['email'] = $formData['email'];
                $arr['telefone'] = $formData['telefone'];
                $arr['cidade'] = $formData['cidade'];
                $arr['mensagem'] = $formData['mensagem'];
                $arr['urlbase']  = $this->_urlbase;
                $arr['modulo'] = 'interesse'; 
                $ok = envioemail::interesseCurso($arr);
                
            } catch (Exception $exc) {
                echo 'error: '.$exc->getMessage();
            }
        }
        
        echo json_encode(array('ok' => $ok));
        
    }

}

